org 100h

;set predefined arguments for the tester
mov ax, [num1]	
mov bx, [num2]

call calc_gcd	

mov ah,4Ch		
int 21h


;Function Description:
;	this function calculates ax % bx
;	and store the result in ax
;Input
;	ax - first number
;	bx - second number
;Output
;	ax = ax % bx
calc_mod: 		
	;while (ax>=bx)
	cmp ax, bx 		
	jb calc_mod_end
		;ax = ax - bx
		sub ax, bx 		
		jmp calc_mod
	calc_mod_end:
ret

;- - - - - - - - - - CALC_GCD FUNCTIOM - - - - - - - - -
;
;this function calculates gcd(ax,bx)
;and store the result in ax
;

;Function Description:
;	this function calculates gcd(ax,bx)
;	and store the result in ax
;Input
;	ax - first number
;	bx - second number
;Output
;	ax = gcd(ax,bx)
calc_gcd: 		
	;if bx == 0, we are done
	cmp bx, 0 		
	je calc_gcd_end
	;ax = ax % bx
	call calc_mod 	
	;swap between ax and bx
	push ax 		
	mov ax, bx
	pop bx
	;calculate gdc(bx,ax % bx)
	jmp calc_gcd 	
	calc_gcd_end:
ret

;init the arguments for the gcd tester
num1 dw 26551	;this is 7 * 3793 (multiplection of two primes)
num2 dw 8071	;this is 7 * 1153 (multiplection of two primes)